<template>
	<!-- 设置 -->
	<view class="vmall-setting">
		<up-cell-group>
			<up-cell v-for="(item,index) in otherCellList"
				:key="index"
				:title="item.title"
				:value="item.value"
				:isLink="item.isLink"
				@click="toNextPage(item)"></up-cell>
		</up-cell-group>
		<view class="button-box px-48">
			<!-- 专营商-显示切换店铺 -->
			<view class="exit-login bg1" v-if="role==2" @click="onChangeShop" >切换店铺</view>
			<view class="exit-login bg2" @click="onExitLogin" :disabled="loading">
				<up-loading-icon class="loading" color="#fff" size="16" :show="loading"></up-loading-icon><text>退出登录</text>
			</view>
		</view>
		<PrivacyPop :showPrivacy="showPrivacy" @privacyclose="privacyclose" />
	</view>
</template>

<script setup>

import { studyApi } from "@/api";
import PrivacyPop from '@/components/PrivacyPop.vue'
import { getStorage } from "@/utils/storage";
let showPrivacy=ref(false)
let role=ref(getStorage('role'))
const otherCellList = ref([
	{
		title: "修改密码",
		value: "",
		isLink: true,
		url: "/pages/user/changepw"
	},
	{
		title: "用户协议",
		value: "",
		isLink: true,
		url: "/pages/agreement/index"
	},
	{
		title: "隐私协议",
		value: "",
		isLink: true,
		type:1,
		url: "/pages/agreement/index"
	}
]);

const loading = ref(false);


const privacyclose=()=>{
  showPrivacy.value = false
  wx.openPrivacyContract()
}
// 去往其他模块
const toNextPage = (item) => {
	if(item.type&&item.type==1){
		// #ifdef MP
		if (wx.getPrivacySetting) {
			wx.getPrivacySetting({
				success: res => {
					if (res.needAuthorization) {
						console.log(res,'')
						showPrivacy.value = true
					} else {
						console.log('已授权')
						wx.openPrivacyContract()
					}
				},
				fail: () => {},
				complete:() => {}
			})    
		}
		// #endif
	}else{
		uni.navigateTo({
			url:item.url
		});
	}
	
};

// 退出登录
const onExitLogin = () => {
	loading.value = true;
	studyApi.exitLogin().then((res) => {
		loading.value = false;
		if(res.code==200){
			uni.removeStorage({
				key: "accountInfo",
				success: function (res) {
					uni.$emit("refresh", { refresh: true });
					// 返回我的页面
					uni.reLaunch({
						url: "/pages/login/login"
					});
				}
			});
		}else{
			uni.showToast({
				title: res.errMsg,
				icon: "none",
				duration: 1000
			});
		}
	})
	
	
};

const onChangeShop = () => {
	uni.navigateTo({ url: `/pagesshop/shop/chooseshop` });
	
}
</script>

<style lang="scss" scoped>
.vmall-setting {
	background-color: #ffffff;
	.button-box{
		width: 100%;
		position: fixed;
		bottom: 70rpx;
		left: 0;
	}
	.exit-login {
		width: 654rpx;
		height: 92rpx;
		line-height: 92rpx;
		background: #D68E44;
		color: #ffffff;
		text-align: center;
		border-radius: 64px;
		font-size: 32rpx;
		margin-bottom: 40rpx;
		display: flex;
    	justify-content: center;
	}
	.bg1{
		background: rgba(253, 236, 219, 1);
		color: rgba(145, 74, 0, 1);
	}
	.exit-login:after {
		border: none;
	}
}
</style>